package me.minetsh.imaging.crop;



import io.reactivex.Completable;
import me.minetsh.imaging.crop.callback.LoadCallback;
import ohos.agp.utils.RectFloat;
import ohos.utils.net.Uri;

public class LoadRequest {

    private float initialFrameScale;
    private RectFloat initialFrameRect;
    private boolean useThumbnail;
    private CropImageView cropImageView;
    private Uri uri;

    /**
     * 构造函数
     *
     * @param cropImageView cropImageView
     * @param uri uri
     */
    public LoadRequest(CropImageView cropImageView, Uri uri) {
        this.cropImageView = cropImageView;
        this.uri = uri;
    }

    /**
     * initialFrameScale
     *
     * @param initialFrameScale initialFrameScale
     * @return this
     */
    public LoadRequest initialFrameScale(float initialFrameScale) {
        this.initialFrameScale = initialFrameScale;
        return this;
    }

    /**
     * initialFrameRect
     *
     * @param initialFrameRect initialFrameRect
     * @return this
     */
    public LoadRequest initialFrameRect(RectFloat initialFrameRect) {
        this.initialFrameRect = initialFrameRect;
        return this;
    }

    /**
     * useThumbnail
     *
     * @param useThumbnail useThumbnail
     * @return this
     */
    public LoadRequest useThumbnail(boolean useThumbnail) {
        this.useThumbnail = useThumbnail;
        return this;
    }

    /**
     * execute
     *
     * @param callback callback
     */
    public void execute(LoadCallback callback) {
        if (initialFrameRect == null) {
            cropImageView.setInitialFrameScale(initialFrameScale);
        }
        cropImageView.loadAsync(uri, useThumbnail, initialFrameRect, callback);
    }

    /**
     * executeAsCompletable
     *
     * @return Completable
     */
    public Completable executeAsCompletable() {
        if (initialFrameRect == null) {
            cropImageView.setInitialFrameScale(initialFrameScale);
        }
        return cropImageView.loadAsCompletable(uri, useThumbnail, initialFrameRect);
    }
}
